package com.chat.view;

import com.chat.Local;
import com.chat.common.Group;
import com.chat.common.User;
import com.chat.io.SetCircle;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.util.Objects;
/*
   好友列表和搜索好友列表的controller类
 */
public class FriendListController {

    public ImageView touxiang;
    public Text id;//用户的昵称
    public Text qianming;
    public String id1;//用户id
    public String state;//标记是好友还是群，1是好友，0是群
    public String status;//在线状态，1是在线，0是离线

    public void setId1(String id1) {
        this.id1 = id1;
    }
    public void setId(String id) {
        this.id.setText(id);
    }
    public void setQianming(String qianming) {
        this.qianming.setText(qianming);
    }
    public void setTouxiang(String username) {
        File file1=new File("D:/chatproject/client/"+username+".png");
        this.touxiang.setImage(new Image("file:"+file1.getAbsolutePath()));
        if(!Objects.equals(id1, "验证消息")) {
            this.touxiang.setClip(new SetCircle().getRectangle(40, 40));
        }
        if(Objects.equals(status, "1")){
              touxiang.setOpacity(1);
        }else touxiang.setOpacity(0.5);
    }
    public void setState(String state) {
        this.state = state;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void friend_msg() {
        if (!Objects.equals(id1, "验证消息")&& Objects.equals(state, "1")) {//点击好友头像的情况
            User user = new User();
            user.setUsername(id1);
            Local.friend = user;
            if(FriendMsgView.loginStage!=null)
                FriendMsgView.loginStage.close();
            try {
                FriendMsgView.start(new Stage());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        else if(!Objects.equals(id1, "验证消息")&& Objects.equals(state, "0")){//点击群头像的情况
            Group group=new Group();
            group.setId(id1);
            Local.group=group;
            try {
                  MainWindowView.loginStage.close();
                GroupMsgView.start(new Stage());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }//好友头像的点击事件

}
